﻿using System.IO;
using Framework.Core.Io;
using Framework.Core.Process.Tasks;
using Xunit;

namespace Framework.Tests.Core.Process.Tasks
{
    public class PsExecTest
    {
        class FakeCommand : ICommand
        {
            public int ProcessId { get { return 0; } }
            public string Name { get { return "Fake"; } }
            public string FileName { get { return "FakePath"; } }
            public string Arguments { get { return "FakeArgs"; } }
            public bool IsNative { get { return false; } }
        }

        class FakeCommandNative : ICommand
        {
            public int ProcessId { get { return 0; } }
            public string Name { get { return "Fake"; } }
            public string FileName { get { return "FakePath"; } }
            public string Arguments { get { return "FakeArgs"; } }
            public bool IsNative { get { return true; } }
        }

        [Fact]
        public void Should_validate_command_with_remote_copy()
        {
            var psExec = new PsExec("remoteMachine", "remoteUser", "remotePassword", new FakeCommand());
            Assert.Equal(@"-accepteula -c -v -u ""remoteUser"" -p ""remotePassword"" ""\\remoteMachine"" ""FakePath"" FakeArgs", psExec.Arguments);
        }

        [Fact]
        public void Should_validate_command()
        {
            var psExec = new PsExec("remoteMachine", "remoteUser", "remotePassword", new FakeCommandNative());
            const string path = @"PsExec.exe";
            Assert.True(File.Exists(path));

            Assert.False(psExec.IsNative);
            Assert.Equal(path, psExec.FileName);
            Assert.Equal("PsExec", psExec.Name);
            Assert.Equal(@"-accepteula -u ""remoteUser"" -p ""remotePassword"" ""\\remoteMachine"" ""FakePath"" FakeArgs", psExec.Arguments);
        }
    }
}
